<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateExam extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('exam', ['comment' => '考试表']);
        $table
            ->addColumn('industry_id', 'integer',array('limit' => 30,'default' => 0,'comment' => '行业类型id'))
            ->addColumn('unit_id', 'integer',array('limit' => 30, 'default' => 0,'comment' => '所属单位id'))
            ->addColumn('create_id', 'integer',array('limit' => 30, 'default' => 1,'comment' => '创建人id'))
            ->addColumn('status', 'boolean',array('limit' => 1, 'default' => 1, 'comment' => '试卷状态(开启or关闭,1or0)'))
            ->addColumn('exam_name', 'string',array('limit' => 50,'null' => true,'comment' => '问卷名称'))
            ->addColumn('exam_type', 'boolean',array('limit' => 1, 'default' => 1, 'comment' => '试卷类型(固定试卷or定时试卷,1or2)'))
            ->addColumn('exam_creation_type', 'boolean',array('limit' => 1, 'default' => 0, 'comment' => '试卷创建类型(人工创建or随机生成or一次生成全部,1or2or3)'))
            ->addColumn('exam_template_id', 'integer',array('limit' => 11, 'default' => 0,'comment' => '试卷模版id'))
            ->addColumn('duration', 'integer',array('limit' => 20,  'default' => 0,'comment' => '时长(试卷类型选择了定时类型时有值，其他时间为0)'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('exam_name'))
            ->create();


        $table = $this->table('exam_stair_type', ['comment' => '问卷一级类别表']);
        $table->addColumn('exam_stair_title', 'string', array('limit' => 120,'null' => true, 'comment' => '问卷一级名称'))
            ->addColumn('year', 'string', array('limit' => 50,'null' => true, 'comment' => '年份'))
            ->addColumn('exam_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '模版id'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('exam_stair_title'))
            ->create();


        $table = $this->table('exam_second_level', ['comment' => '问卷二级分类']);
        $table->addColumn('exam_second_title', 'string', array('limit' => 220, 'null' => true,'comment' => '简称名称'))
            ->addColumn('year', 'string', array('limit' => 50,'null' => true, 'comment' => '年份'))
            ->addColumn('exam_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '问卷id'))
            ->addColumn('exam_stair_type_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '问卷一级类别表类别id'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('exam_second_title'))
            ->create();


        $table = $this->table('exam_detail', ['comment' => '问卷类别简称详情表']);
        $table->addColumn('exam_detail_title', 'string', array('limit' => 320, 'null' => true,'comment' => '简称详情名称'))
            ->addColumn('year', 'string', array('limit' => 50, 'null' => true,'comment' => '年份'))
            ->addColumn('desc', 'string', array('limit' => 220, 'comment' => '标准描述'))
            ->addColumn('deduct_marks_standard', 'string', array('limit' => 220, 'comment' => '扣分标准'))
            ->addColumn('once_deduct_marks', 'string', array('limit' => 120, 'comment' => '单次扣分'))
            ->addColumn('most_deduct_marks', 'string', array('limit' => 120, 'comment' => '最多扣分'))
            ->addColumn('exam_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '问卷id'))
            ->addColumn('exam_stair_type_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '一级'))
            ->addColumn('exam_second_level_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '二级'))
            ->addColumn('create_id', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '创建人id'))
            ->addTimestamps()
            ->addSoftDelete()
            ->addIndex(array('exam_detail_title'))
            ->create();
    }
}
